package com.onlyphoto.onlymall.mvp.presenter

import android.content.Context
import com.onlyphoto.onlymall.base.BaseEntity
import com.onlyphoto.onlymall.base.BaseNetworkResponse
import com.onlyphoto.onlymall.base.BaseObserver

import com.onlyphoto.onlymall.mvp.contract.CLoginBySms
import com.onlyphoto.onlymall.mvp.model.MLoginBySmsImpl
import com.onlyphoto.onlymall.base.BasePresenter
import com.onlyphoto.onlymall.bean.response.UserInfoBean


class PLoginBySmsImpl(mContext: Context, mView: CLoginBySms.IVLoginBySms) : BasePresenter<CLoginBySms.IVLoginBySms, MLoginBySmsImpl>(mContext, mView, MLoginBySmsImpl()), CLoginBySms.IPLoginBySms {
    override fun getVerify(getType: Int, phone: String) {
        mModel.getVerify(getType, phone, object :BaseObserver<Void>(mContext.get()){
            override fun onSuccess(data: Void?, msg: String?) {
                mView.getVerifySuccess()
            }

            override fun onCodeError(t: BaseNetworkResponse<Void>?) {
                if (t?.error_code == 1) {
                    mView.showMsg(t.msg!!)
                } else {
                    mView.getVerifyFail()
                }
            }

            override fun onFailure(e: Throwable?) {
                mView.getVerifyFail()
            }

            override fun onRequestStart() {
            }

            override fun onFinally() {
            }

        })
    }

    override fun loginBySms() {
        var bean = mView.getLoginEntity()
        mModel.loginBySms(bean, object :BaseObserver<UserInfoBean>(mContext.get()){
            override fun onSuccess(data: UserInfoBean?, msg: String?) {
                mView.loginSuccess(data!!)
            }

            override fun onCodeError(t: BaseNetworkResponse<UserInfoBean>?) {
            }

            override fun onFailure(e: Throwable?) {
            }

            override fun onRequestStart() {
                mView.showLoading()
            }

            override fun onFinally() {
                mView.hideLoading()
            }

        })
    }
}
